﻿using King.Box.Utils.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace King.Box.Utils.Global
{
    public class GlobalConfig
    {
        #region Port
        public static int Port
        {
            get
            {
                return ConfigUtil.GetValue<int>("Port", 1234);
            }
        }
        #endregion

        #region SecrityKey
        public static string SecureKey
        {
            get
            {
                return ConfigUtil.GetValue<string>("SecureKey", "kingbox");
            }
        }
        #endregion

        #region ApiAddress
        public static string ApiAddress
        {
            get
            {
                var address = ConfigUtil.GetValue("ApiAddress");
                if (string.IsNullOrEmpty(address))
                    return string.Empty;

                if (!address.EndsWith("/"))
                    address += '/';
                return address;
            }
        }
        #endregion

        #region TokenCache
        public static int TokenCacheMinute
        {
            get
            {
                return ConfigUtil.GetValue<int>("TokenCacheMinute", 120);
            }
        }
        #endregion

        #region OAuth
        public static string ClientId
        {
            get
            {
                return ConfigUtil.GetValue("ClientId");
            }
        }

        public static string ClientSecret
        {
            get
            {
                return ConfigUtil.GetValue("ClientSecret");
            }
        }

        public static Dictionary<string, string> ClientDictionary
        {
            get
            {
                try
                {
                    string config = ConfigUtil.GetValue("Client");
                    if (string.IsNullOrEmpty(config))
                        return new Dictionary<string, string>();

                    var param = config.Split(';');
                    var data = new Dictionary<string, string>();
                    param.ToList().ForEach(x =>
                    {
                        var val = x.Split(',');

                        if (val.Length == 2)
                            data.Add(val[0], val[1]);
                    });
                    return data;
                }
                catch
                {
                    return new Dictionary<string, string>();
                }
            }
        }
        #endregion

        #region WeiXin
        public static string WX_Token
        {
            get
            {
                return ConfigUtil.GetValue("WXToken");
            }
        }

        public static string WX_EncodingAESKey
        {
            get
            {
                return ConfigUtil.GetValue("WXEncodingAESKey");
            }
        }

        public static string WX_AppId
        {
            get
            {
                return ConfigUtil.GetValue("WXAppId");
            }
        }
        #endregion

        #region Mail
        public static string Mail_Server
        {
            get
            {
                return ConfigUtil.GetValue("MailServer","smtp.qq.com");
            }
        }

        public static string Mail_UserName
        {
            get
            {
                return ConfigUtil.GetValue("MailUserName", "vongzh@qq.com");
            }
        }

        public static string Mail_UserPwd
        {
            get
            {
                return ConfigUtil.GetValue("MailUserPwd", "cdngbboobrvcbjfj");
            }
        }
        #endregion
    }
}
